﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true" CodeFile="ManageClass.aspx.cs" Inherits="Default2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div style="height: 600px">
        <br />

        <asp:Button ID="Button1" runat="server" Text="新建班级" onclick="Button1_Click" 
            UseSubmitBehavior="False" />
        <asp:Panel ID="Panel1" runat="server" Visible="False">
            <asp:DropDownList ID="DropDownList1" runat="server" 
                DataSourceID="XmlDataSource1" DataTextField="name" DataValueField="name">
            </asp:DropDownList>
            <asp:DropDownList ID="DropDownList2" runat="server" 
                DataTextField="name" DataValueField="name" DataSourceID="XmlDataSource2">
            </asp:DropDownList>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="确定" />
            <asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="取消" />
            <asp:Label ID="Label1" runat="server" style="color: #FF0000"></asp:Label>
        </asp:Panel>
        <br />
        <asp:ListView ID="ListView1" runat="server" DataKeyNames="id" 
            DataSourceID="SqlDataSource1" EnableModelValidation="True" 
            EnableTheming="True" 
            >
            <AlternatingItemTemplate>
                <div style="background-color: #FAFAD2;color: #284775;">
                
                    <table style="margin: 5px 10px 5px 10px;width:70%">
                        <tr>
                            <td colspan="2">

                            <a href='managecontact.aspx?class=<%# Eval("class") %>' ><%# Eval("class") %></a>
                                
                            </td>
                        </tr>
                        <tr>
                            <td>
                            系别:<asp:Label ID="departmentLabel" runat="server" 
                        Text='<%# Eval("department") %>' />        
                            </td>
                            <td>
                             年级:<asp:Label ID="gradeLabel" runat="server" Text='<%# Eval("grade") %>'  />
                   
                            </td>
                        </tr>
                        <tr>
                            <td>
                            管理员:<asp:Label ID="ownerLabel" runat="server" Text='<%# Eval("owner") %>'  />
                            </td>
                            <td colspan="2">创建日期:<asp:Label ID="createdLabel" runat="server" Text='<%# Eval("created") %>'   />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                                <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="编辑" />
                    <asp:Button ID="DeleteButton" OnClientClick="return confirm('确定要删除该班级以及相关的联系人信息吗？')" runat="server" CommandName="Delete" Text="删除" />
                            </td>
                        </tr>
                    </table>

                </div>
            </AlternatingItemTemplate>
            <EditItemTemplate>
                <div style="background-color: #FFCC66;color: #000080;">
                    <table  style="margin: 5px 10px 5px 10px;">
                        <tr>
                            <td>
                            班级:
                            <asp:TextBox ID="classTextBox" runat="server" Text='<%# Bind("class") %>' />
                            <br />
                            系别:
                            <asp:TextBox ID="departmentTextBox" runat="server" 
                                Text='<%# Bind("department") %>' />                    
                            <br />
                            年级:
                            <asp:TextBox ID="gradeTextBox" runat="server" Text='<%# Bind("grade") %>' />
                            <br />
                            </td>
                        </tr>
                        <tr>
                            <td>
                  
                            <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="更新" />
                            <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="取消" />
                            </td>
                        </tr>
                    </table>
                </div>
            </EditItemTemplate>
            <EmptyDataTemplate>
                未返回数据。
            </EmptyDataTemplate>
            <InsertItemTemplate>
                <li style="">class:
                    <asp:TextBox ID="classTextBox" runat="server" Text='<%# Bind("class") %>' />
                    <br />
                    owner:
                    <asp:TextBox ID="ownerTextBox" runat="server" Text='<%# Bind("owner") %>' />
                    <br />
                    department:
                    <asp:TextBox ID="departmentTextBox" runat="server" 
                        Text='<%# Bind("department") %>' />
                    <br />
                    grade:
                    <asp:TextBox ID="gradeTextBox" runat="server" Text='<%# Bind("grade") %>' />
                    <br />
                    created:
                    <asp:TextBox ID="createdTextBox" runat="server" Text='<%# Bind("created") %>' />
                    <br />
                    <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="插入" />
                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="清除" />
                </li>
            </InsertItemTemplate>
            <ItemSeparatorTemplate>
                <br />
            </ItemSeparatorTemplate>
            <ItemTemplate>
                <div style="background-color: #FFFBD6;color: #333333;">
                    <table style="margin: 5px 10px 5px 10px; width:70%">
                        <tr>
                            <td colspan="2">
                            <a href='managecontact.aspx?class=<%# Eval("class") %>' ><%# Eval("class") %></a>
                            </td>
                        </tr>
                        <tr>
                            <td>
                            系别:<asp:Label ID="departmentLabel" runat="server" 
                        Text='<%# Eval("department") %>' />        
                            </td>
                            <td>
                             年级:<asp:Label ID="gradeLabel" runat="server" Text='<%# Eval("grade") %>'  />
                   
                            </td>
                        </tr>
                        <tr>
                            <td>
                            管理员:<asp:Label ID="ownerLabel" runat="server" Text='<%# Eval("owner") %>'  />
                            </td>
                            <td colspan="2">创建日期:<asp:Label ID="createdLabel" runat="server" Text='<%# Eval("created") %>'   />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                                <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="编辑" />
                    <asp:Button ID="DeleteButton" OnClientClick="return confirm('确定要删除该班级以及相关的联系人信息吗？')" runat="server" CommandName="Delete" Text="删除" />
                            </td>
                        </tr>
                    </table>
                </div>
            </ItemTemplate>
            <LayoutTemplate>
                
                <div ID="itemPlaceholderContainer" runat="server" 
                    style="font-family: Verdana, Arial, Helvetica, sans-serif; height: 520px;">
                    
                    <div runat="server" id="itemPlaceholder" />
                </div>
                <div style="font-family: Verdana, Arial, Helvetica, sans-serif; text-align: center; background-color: #FFCC66; color: #333333;">
                    <asp:DataPager ID="DataPager1" runat="server" PageSize="4">
                        <Fields>
                            <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                                ShowLastPageButton="True" />
                        </Fields>
                    </asp:DataPager>
                </div>
            </LayoutTemplate>
            <SelectedItemTemplate>
                <div style="background-color: #FFCC66;font-weight: bold;color: #000080;">
                           <table style="margin: 10px;width:70%">
                        <tr>
                            <td colspan="2">
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("class") %>'   /> 
                            </td>
                        </tr>
                        <tr>
                            <td>
                            系别:<asp:Label ID="departmentLabel" runat="server" 
                        Text='<%# Eval("department") %>' />        
                            </td>
                            <td>
                             年级:<asp:Label ID="gradeLabel" runat="server" Text='<%# Eval("grade") %>'  />
                   
                            </td>
                        </tr>
                        <tr>
                            <td>
                            管理员:<asp:Label ID="ownerLabel" runat="server" Text='<%# Eval("owner") %>'  />
                            </td>
                            <td colspan="2">创建日期:<asp:Label ID="createdLabel" runat="server" Text='<%# Eval("created") %>'   />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                                <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="编辑" />
                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="删除" OnClientClick="return confirm('确定要删除该班级以及相关的联系人信息吗？')" />
                            </td>
                        </tr>
                    </table>
                </div>
            </SelectedItemTemplate>
        </asp:ListView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConflictDetection=OverwriteChanges 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            DeleteCommand="DELETE FROM [class] WHERE [id] = @original_id " 
            InsertCommand="INSERT INTO [class] ([class], [owner], [department], [grade], [created]) VALUES (@class, @owner, @department, @grade, @created)" 
            OldValuesParameterFormatString="original_{0}" 
            SelectCommand="SELECT * FROM [class]" 
            
            UpdateCommand="UPDATE [class] SET [class] = @class,  [department] = @department, [grade] = @grade WHERE [id] = @original_id ">
            <DeleteParameters>
                <asp:Parameter Name="original_id" Type="Int32" />
                <asp:Parameter Name="original_class" Type="String" />
                <asp:Parameter Name="original_owner" Type="String" />
                <asp:Parameter Name="original_department" Type="String" />
                <asp:Parameter Name="original_grade" Type="String" />
                <asp:Parameter DbType="Date" Name="original_created" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="class" Type="String" />
                <asp:Parameter Name="owner" Type="String" />
                <asp:Parameter Name="department" Type="String" />
                <asp:Parameter Name="grade" Type="String" />
                <asp:Parameter DbType="Date" Name="created" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="class" Type="String" />
                <asp:Parameter Name="owner" Type="String" />
                <asp:Parameter Name="department" Type="String" />
                <asp:Parameter Name="grade" Type="String" />
                <asp:Parameter DbType="Date" Name="created" />
                <asp:Parameter Name="original_id" Type="Int32" />
                <asp:Parameter Name="original_class" Type="String" />
                <asp:Parameter Name="original_owner" Type="String" />
                <asp:Parameter Name="original_department" Type="String" />
                <asp:Parameter Name="original_grade" Type="String" />
                <asp:Parameter DbType="Date" Name="original_created" />
            </UpdateParameters>
        </asp:SqlDataSource>
            <asp:XmlDataSource ID="XmlDataSource1" runat="server" 
            DataFile="~/XMLFile.xml" XPath="school/department">
            </asp:XmlDataSource>
            <asp:XmlDataSource ID="XmlDataSource2" runat="server" 
            DataFile="~/XMLFile.xml" XPath="school/grade">
            </asp:XmlDataSource>
    </div>
    </asp:Content>

